package cn.online.taxi.api.driver.controller;

import cn.online.taxi.common.pojo.Result;
import cn.online.taxi.common.utils.ResultUtil;
import cn.online.taxi.order.service.service.GrabService;
import cn.online.taxi.order.service.service.OrderService;
import cn.online.taxi.order.service.service.impl.GrabRedisRedissonService;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author BinBini
 * @Date 2021/04/27 17:28
 * @Version 1.0
 */
@RestController
@Api(value = "司机订单")
public class OrderController {

    @Reference
    private GrabService grabService;
    @Reference
    private OrderService orderService;

    @RequestMapping(value = "/driver/order/grab", method = RequestMethod.POST)
    @ApiOperation(value = "司机抢单")
    public Result<Object> grabOrder(String orderNumber, Integer driverId, String driverToken) {
        boolean result = grabService.grabOrder(orderNumber, driverId, driverToken);
        return new ResultUtil<Object>().setData(result);
    }

    @RequestMapping(value = "/driver/order/receiving", method = RequestMethod.POST)
    @ApiOperation(value = "司机去接乘客")
    public Result<Object> receiving(String orderNumber, Integer driverId) {
        boolean result = orderService.receiving(orderNumber, driverId);
        return new ResultUtil<Object>().setData(result);
    }

    @RequestMapping(value = "/driver/order/start", method = RequestMethod.POST)
    @ApiOperation(value = "开始行程")
    public Result<Object> startJourney(String orderNumber, Integer driverId, String phone, String receivePassengerLongitude, String receivePassengerLatitude) {
        boolean result = orderService.startJourney(orderNumber, driverId, phone, receivePassengerLongitude, receivePassengerLatitude);
        return new ResultUtil<Object>().setData(result);
    }

    @RequestMapping(value = "/driver/order/end", method = RequestMethod.POST)
    @ApiOperation(value = "手动结束行程")
    public Result<Object> endJourney(String orderNumber, Integer driverId, String passengerGetoffLongitude, String passengerGetoffLatitude) {
        boolean result = orderService.endJourney(orderNumber, driverId, passengerGetoffLongitude, passengerGetoffLatitude);
        return new ResultUtil<Object>().setData(result);
    }

    @RequestMapping(value = "/driver/order/charge", method = RequestMethod.POST)
    @ApiOperation(value = "发起收款")
    public Result<Object> charge(String orderNumber, Integer driverId) {
        boolean result = orderService.charge(orderNumber, driverId);
        return new ResultUtil<Object>().setData(result);
    }

}
